package org.code.mallspringboot.controller;

import org.code.mallspringboot.pojo.PmsProduct;
import org.code.mallspringboot.service.PmsProductService;
import org.code.mallspringboot.vo.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/home")
public class HomeController {

    @Autowired
    private PmsProductService pmsProductService;

    @GetMapping("/newProductList")
    public CommonResult fetchNewProductList(@RequestParam(value = "pageNum",defaultValue = "1") int pageNum,
                                            @RequestParam(value = "pageSize",defaultValue = "6")int pageSize){
        List<PmsProduct> list = pmsProductService.list(pageNum, pageSize);
        if (!list.isEmpty()){
            return CommonResult.success(list);
        }
        return CommonResult.failed("没有更多了!");
    }
}
